package com.demoproject.demo.service;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Service
public class RedisService {

    @Resource
    private RedisTemplate<String,String> stringRedisTemplate;

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public void test() {
        String redis = stringRedisTemplate.opsForValue().get("REDIS_03");
        if (StringUtils.isNotBlank(redis)) {
            logger.info("进入缓存");
            String toString = stringRedisTemplate.opsForValue().get("REDIS_03");
            System.out.println("缓存数据为:" + toString);
            stringRedisTemplate.delete("REDIS_03");
        }
        // stringRedisTemplate.opsForHash().put("REDIS", "id", "123");
        stringRedisTemplate.opsForValue().set("REDIS_03", "id", 1, TimeUnit.HOURS);
    }
}
